#ifndef __BSTREE_H_
#define __BSTREE_H_
#include <stdbool.h>
#include "common.h"
#define RED true
#define BLACK false

typedef struct RbtreeNode
{
    ELEMENTTYPE val;
    bool color;
    struct RbtreeNode *parent;
    struct RbtreeNode *left;
    struct RbtreeNode *right;
} RbtreeNode;

typedef struct Rbtree
{
    RbtreeNode *root;
    /*所有为空的的节点都为leaf节点
    默认节点为黑色，不存放实际数据*/
    RbtreeNode *leaf;
    /* 树的节点个数 */
    int size;
    int (*compare)(ELEMENTTYPE, ELEMENTTYPE);
    void (*printTree)(ELEMENTTYPE);
} Rbtree;
/*红黑树初始化*/
int rbtreeInit(Rbtree **rbtree, int (*pCompare)(ELEMENTTYPE, ELEMENTTYPE), void (*printTree)(ELEMENTTYPE));

/*红黑树插入*/
int rbtreeInsert(Rbtree *rbtree, ELEMENTTYPE data);

/*红黑树查找*/
RbtreeNode *rbtreeSearch(Rbtree *rbtree, ELEMENTTYPE data);

/*红黑树删除*/
int rbtreeRemove(Rbtree *rbtree, ELEMENTTYPE data);

/*红黑树前序遍历*/
int rbtreePrePrint(Rbtree *rbtree);

/*红黑树中序遍历*/
int rbtreeInorderPrint(Rbtree *rbtree);

/*红黑树后序遍历*/
int rbtreePostPrint(Rbtree *rbtree);

/*红黑树层序遍历*/
int rbtreeLevelPrint(Rbtree *rbtree);

/*红黑树获取高度*/
int rbtreeGetHeight(Rbtree *rbtree, int *height);

/*红黑树销毁*/
int rbtreeDestroy(Rbtree *rbtree);
#endif /*__BSTREE_H_*/